Hard disk drives are commonly used in personal computers, servers, video recorders, and many other kind of electronic devices for mass storage. Mass storage is used to store large amounts of data that is typically copied to a faster random-access memory such as a dynamic-random-access memory (DRAM) for use by a processor. While the processor's DRAM is randomly accessible, mass storage is block-accessible. An entire block of data must be read or written from the mass storage device. A RAM may allow reading and writing of individual bytes or words of 4 or 8 bytes, while a mass storage device requires that a sector or 512 bytes or more be read or written together.
While mass storage devices are useful, they are much slower than the processor's main DRAM memory. Seek times to locate a sector to access may depend on the physical rotation of a disk platter, rather than just the movement of electrons. The large amount of data in a sector also increases delays to access data.
A mass storage device such as a hard disk may employ a cache to improve performance. A DRAM or SRAM cache can store data to be written to the hard disk at a later time. Recently-accessed data can be stored in the RAM cache, allowing reads to be supplied from the RAM cache rather than from the slower hard disk.
Flash memory may also be used as a mass storage device in lieu of a hard disk. Flash-memory arrays are also block-accessible, but have a much faster access time than rotating media such as a hard disk. However, since flash memory chips are block-addressable rather than randomly-accessible, flash is not as easy to use for a cache as DRAM or SRAM.
Since power can fail before the data from the cache is copied onto the hard disk, cached data can be lost or corrupted if the cache is volatile. DRAM or SRAM may use a battery backup that provides enough energy to finish writing back data when the power fails. Alternatively, flash or other non-volatile memory may be used for the cache.
What is desired is a cache for a hard disk or other rotational mass storage device that uses flash memory for cache storage. A flash-memory cache controller that caches data for a rotational mass-storage device is desirable. A caching technique that arranges flash-memory blocks into foreground and background areas is desirable.